const express = require("express");
const app = express();
app.all("*", function (req, res, next) {
  res.header("Access-Control-Allow-Origin", "*");
  res.header("Access-Control-Allow-Header", "X-Requested-with,Content-Type");
  res.header("Access-Control-Allow-Methods", "PUT,POST,GET,DELETE,OPTIONS");
  next();
});
app.get("/shoplist", (req, res) => {
  const data = {
    shop: [
      {
        goodName: "飞机",
        price: 1230
      },
      {
        goodName: "电脑",
        price: 10000
      }
    ]
  };
  res.send(JSON.stringify(data));
});
app.get("/all", function (req, res) {
  const data = {
    all: "123",
    money: "123123"
  };
  res.send(JSON.stringify(data));
});
let bodyparser = require("body-parser");
// parse application/x-www-form-urlencoded
app.use(bodyparser.urlencoded({ extended: false }));
// parse application/json
app.use(bodyparser.json());
app.post("/login", (req, res) => {
  console.log(req.body);
  const data = {
    shop: [
      {
        goodName: "飞机",
        price: 1230
      },
      {
        goodName: "电脑",
        price: 10000
      }
    ]
  };
  res.send(JSON.stringify(data));
});
app.listen("1020");
// express 中间件
